/**
 * pinia 存贮区域
 */

 import { defineStore} from "pinia";

 import WebStorageCache from "web-storage-cache"; 
 
 
 const cache=new WebStorageCache({
     storage:window.localStorage
 })
 
 export const mainStore=defineStore("main",{
     state(){
         return{
         token:null,
         loginInfoData:null,
         }
     }, 
     //pinia没有mutations 省略了
     actions:{
         setToken(token){
             this.token=token;
         },
         setLoginUserInfo(loginInfoData){
             this.loginInfoData=loginInfoData;
         },
         setIsCollapse(flag){
             this.isCollapse=flag;
         },
         logOut(){
             this.token=null;
             this.loginInfoData=null;
         },
     },
     //配置状态的持久化
     persist:{
         key:"main",
         storage:{
             getItem:key=>cache.get(key),
             setItem:(key,value)=>cache.set(key,value,{exp:60 * 60 *24}),
             removeItem:key=>cache.delete(key),
             clear:()=>cache.clear()
         },
         //指定需要持久化得字段
         paths:["token","loginInfoData"]
     }
 })